package com.saasitems.common.utils;

import org.apache.commons.lang3.StringUtils;

import java.text.DecimalFormat;
import java.util.Scanner;

/**
 * Created by Administrator on 2017/4/24.
 */
public class CheckUtil {

    /**
     * 校验原文
     * @param content
     * @return
     */
    public static String checkContent(String content) {
        String ret = "";
        if (StringUtils.isBlank(content)) {
            return "内容为空";
        }

        int textareaCols = Integer.parseInt(PropertiesUtil.newInstance().getStringByKey("TEXTAREA.COLS"));
//        // 以回车为分隔符
//        String[] arr = content.split("\n|\r");
//        int rowIndex = 0;
//        for (String s : arr) {
//            rowIndex++;
//            if (s.length() > textareaCols) {
//                ret = "第" + rowIndex + "行，为" + s.length() + "个字符，超出最大限制!";
//                break;
//            }
//        }
        Scanner sc = new Scanner(content);
        int rowIndex = 0;
        while(sc.hasNext()){
            rowIndex++;
            String s = sc.nextLine();
            if (s.length() > textareaCols) {
                ret = "第" + rowIndex + "行，为" + s.length() + "个字符，超出最大限制!";
                break;
            }
        }
        return ret;
    }
}
